﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using eProject.ViewModel;

namespace eProject.View
{
    /// <summary>
    /// Interaction logic for CreateEmployeeDialog.xaml
    /// </summary>
    public partial class CreateEmployeeDialog
    {
        public string EmployeeName { get; set; }

        public string EmployeeSurname { get; set; }

        public string EmployeePhone { get; set; }

        public string EmployeeEmail { get; set; }

        public CreateEmployeeDialog(CommonManager manager, EmployeeViewModel employee)
            : this(manager)
        {
            Title = Properties.Resources.EditEmployeeDialogHeader;
            EmployeeName = employee.Name;
            EmployeeSurname = employee.Surname;
            EmployeePhone = employee.PhoneNumber;
            EmployeeEmail = employee.EMail;
            rule1.CurrentValue = employee.EMail;
        }

        public CreateEmployeeDialog(CommonManager manager)
        {
            InitializeComponent();            
            Title = Properties.Resources.CreateEmployeeDialogHeader;
            DataContext = this;
            EmployeeName = "";
            EmployeeSurname = "";
            EmployeePhone = "";
            EmployeeEmail = "";
            Loaded += delegate
                          {
                              var email = emailTextBox.GetBindingExpression(TextBox.TextProperty);
                              var name = nameTextBox.GetBindingExpression(TextBox.TextProperty);
                              var surname = surnameTextBox.GetBindingExpression(TextBox.TextProperty);
                              var phone = phoneTextBox.GetBindingExpression(TextBox.TextProperty);
                              if (name != null) name.UpdateSource();
                              if (surname != null) surname.UpdateSource();
                              if (phone != null) phone.UpdateSource();
                              if (email != null) email.UpdateSource();
                          };
            rule1.Enumerable = manager.Employees;
            rule1.Converter = e => e.EMail;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }      
    }
}
